package com.dream.base.filter;

import android.app.Activity;
import android.view.View;

import com.dream.base.tools.LogUtil;

/**
 * @author: WangKunHui
 * Date: 2017/8/17 18:07
 * Desc:
 * E-mail:life_artist@163.com
 */
public abstract class ClickEventFilter {

    /**
     * 默认所有的按钮都需要跳转
     */
    private boolean needCheck = true;

    /**
     * 连续点击是否有间隔时间
     */
    private boolean needPeriod = true;

    public void setNeedCheck(boolean needCheck) {
        this.needCheck = needCheck;
    }

    public ClickEventFilter setNeedPeriod(boolean needPeriod) {
        this.needPeriod = needPeriod;

        return this;
    }

    public boolean isNeedPeriod() {
        return needPeriod;
    }

    public final void onPreClick(Activity activity, View v) {
        if (needCheck) {
            if (!isNormal(activity, v)) {

                return;
            }
        }

        if (needPeriod) {

            if (!ClickUtil.isEffectiveClick()) {
                onClick(v);
            }
        } else {
            onClick(v);
        }
    }

    private boolean isNormal(Activity activity, View v) {

        return true;
    }

    public abstract void onClick(View v);

    /**
     * 自定义点击事件
     */
    public static abstract class OnTvmOnClickListener implements View.OnClickListener {

        private ClickEventFilter clickAction = new ClickEventFilter() {

            @Override
            public void onClick(View v) {
                LogUtil.d("MainActivityTab", "setOnClickListener5");
                onTvmClick(v);
            }
        };

        public void setCheck(boolean isCheck) {
            clickAction.setNeedCheck(isCheck);
        }

        @Override
        public void onClick(View v) {
            LogUtil.d("MainActivityTab", "setOnClickListener3");
        }

        public abstract void onTvmClick(View v);
    }

}
